package com.itcast.stargraph.utils;

import com.openai.client.OpenAIClient;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Author katana
 * @Date 2025/6/11 10:12
 */
@Component
public class OllamaUtils {
    @Autowired
    private OpenAIClient openAIClient;
    
    @Value("${qwen.model}")
    private String model;
    
    @Value("${qwen.apikey}")
    private String apiKey;
    public String translate(String prompt) {
        ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
                //system非常重要，影响了后续AI会话的行为模式。
                .addSystemMessage("你是一个专业的翻译助手，专注于中英互译。接下来用户提问的内容你只需回答翻译后的英文结果！")
                .addUserMessage(prompt)
                .model(model)
                .build();
        System.out.println(apiKey);
        ChatCompletion chatCompletion = openAIClient.chat().completions().create(params);
        return chatCompletion.choices().get(0).message().content().orElse(null);
    }
    
}
